package com.socialrss.adapters;

import java.util.List;  

import com.socialrss.R;
import com.socialrss.viewlisteners.NotificationItem;

import android.app.Activity;  
import android.content.Context;
import android.support.v4.widget.SimpleCursorAdapter.ViewBinder;
import android.view.LayoutInflater;  
import android.view.View;  
import android.view.ViewGroup;  
import android.widget.ArrayAdapter;  
import android.widget.ImageView;  
import android.widget.TextView;  

public class CustomListAdapter extends ArrayAdapter<NotificationItem> {  
   private Activity context;  
   private ListItemRow itemRow;  
   private List<NotificationItem> list;
   private LayoutInflater inflater;
   public CustomListAdapter(Activity context, List<NotificationItem> list) {  
	  super(context, R.layout.activity_main, list);  
      this.context = context;  
      this.list = list;  
   }
   
   @Override  
   public View getView(int position, View convertView, ViewGroup parent) {
	  inflater = (LayoutInflater) context
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
      View rowView = convertView;  
      if (rowView == null) {  
         itemRow = new ListItemRow();
         rowView = inflater.inflate(R.layout.notification_list_cell, null, true);  
         itemRow.photo = (ImageView) rowView.findViewById(R.id.photo);  
         itemRow.title = (TextView) rowView.findViewById(R.id.title);
//         itemRow.title = (TextView) rowView.
//         itemRow.title = (TextView) list.get(position).littleText;
//         itemRow.title.setText(list.get(position).littleText);
         rowView.setTag(itemRow);  
      } else {  
         itemRow = (ListItemRow) rowView.getTag();  
      }  
      // element of the line; photo and title
      int iconType = list.get(position).photoType;
      if(iconType == 0){
    	  itemRow.photo.setImageResource(R.drawable.facebook_icon);
      }
      else if(iconType == 1){
    	  itemRow.photo.setImageResource(R.drawable.twitter_icon);
      }
      else if(iconType == 2){
    	  itemRow.photo.setImageResource(R.drawable.google_plus_icon);
      }
      else if(iconType == 3){
    	  itemRow.photo.setImageResource(R.drawable.instagram_icon);
      }
      else{
    	  itemRow.photo.setImageResource(R.drawable.ic_launcher);  
      }
      String word = list.get(position).littleText;
      if(list.get(position).text.length() > 25){
    	  word = (word + "...");
      }
      itemRow.title.setText(word);  
      return rowView;  
   }  
   // components that are in the list
   private class ListItemRow {  
      private ImageView photo;  
      private TextView title;
   }  
}  